<?php
Load('extend');

class AdminAction extends Action{
	var $name = 'Admin';
	var $position = "我的面板";
	
    public function publicAssign(){
    	header("Access-Control-Allow-Origin: *");
    	$this->assign("username",Session::get('username'));				//用户名
		$this->userStyle(Session::get('userstyle'));					//用户类型
		$this->assign("styleName",Session::get("styleName"));
		$this->assign("webName",Session::get("webName"));
		$this->assign("webUrl",C('WEB_URL'));
		$this->assign("userLoginIp",Session::get("userLoginIp"));
		$this->assign("userLoginTime",Session::get("userLoginTime"));
    }
    
	public function index(){			//首页
		
		if (Session::is_set('username')){
			$this->publicAssign(); 
			$this->display();
		}else {
			$this->login();
		}
	}
	
	public function head($class = null){
		if($class){
			$url = C('HEAD_OFF_URL'); 
		}else{
			$url = C('HEAD_URL'); 
		}
		$buffer = ""; 
		$handle = @fopen($url,"r"); 
		if($handle) { 
			while (!feof($handle)) { 
				$buffer .= fgets($handle, 4096); 
			} 
			fclose($handle); 
		} 
		$this->assign('head',$buffer); 
	}
	/*
	 * 判断左边载入哪个页面
	 */
	public function left(){					//左边
		$this->publicAssign(); 
		if ($_GET['menuid']){
			switch ($_GET['menuid']){
				case 10:
					break ;
				case 1:
					$this->left_config();
					return ;
				case 2:
					$this->left_message();
					return ;
				case 3:
					$this->left_pic();
					return ;
				case 4:
					$this->left_member();
					return ;
			}
		}
		header('Content-type:text/html;charset=utf-8');
		header("Access-Control-Allow-Origin: *");
		$this->display();
	}
	/*
	 * left页面信息
	 */
	public function left_config(){
    	header("Access-Control-Allow-Origin: *");
		header('Content-type:text/html;charset=utf-8');
		$this->display("tpl/default/admin/left_config.html");
	}
	/*
	 * left留言板
	 */
	public function left_message(){
    	header("Access-Control-Allow-Origin: *");
		header('Content-type:text/html;charset=utf-8');
		$this->display("tpl/default/admin/left_message.html");
	}
	/*
	 * left图片管理
	 */
	public function left_pic(){
    	header("Access-Control-Allow-Origin: *");
		header('Content-type:text/html;charset=utf-8');
		$this->display("tpl/default/admin/left_pic.html");
	}
	/*
	 * left会员信息
	 */
	public function left_member(){
    	header("Access-Control-Allow-Origin: *");
		header('Content-type:text/html;charset=utf-8');
		$this->display("tpl/default/admin/left_member.html");
	}
	/*
	 * 右边首页
	 */
	public function right_main(){	
    	header("Access-Control-Allow-Origin: *");			
		header('Content-type:text/html;charset=utf-8');
		$this->publicAssign();
		
		$config = M("Config");
		$array = $config->select();
		$web_name = $array[1]['config_value'];
		$banquan = $array[3]['config_value'];
		$developer = $array[4]['config_value'];
		$this->assign('web_name',$web_name);
		$this->assign('banquan',$banquan);
		$this->assign('developer',$developer);
		
		$this->display();
	}
	/*
	 * 删除缓存
	 */
	public function right_deleteCache(){
		header('Content-type:text/html;charset=utf-8');
		if ($_POST['dosubmit']) {
		  $dir = "../courses/Runtime";
		  if($this->deldir($dir)) {
		    echo "删除缓存成功！";
		  } else {
		    echo "删除缓存失败！";
		  }
		}else {
			$this->display();
		}
	}
	/*
	 * right页面信息
	 */
	public function right_config(){				
		header('Content-type:text/html;charset=utf-8');
		$this->publicAssign();
		$config = M("Config");
		$array = $config->select();
		$web_name = $array[1]['config_value'];
		$foot = $array[2]['config_value'];
		$banquan = $array[3]['config_value'];
		$developer = $array[4]['config_value'];
		
		$this->assign('web_name',$web_name);
		$this->assign('foot',$foot);
		$this->assign('banquan',$banquan);
		$this->assign('developer',$developer);
		$this->display();
	}
	/*
	 * right修改页面信息
	 */
	public function edit_config(){
		header('Content-type:text/html;charset=utf-8');
		$this->publicAssign();
		$config = M("Config");
		$array = $config->select();
		$web_name = $array[1]['config_value'];
		$foot = $array[2]['config_value'];
		$banquan = $array[3]['config_value'];
		$developer = $array[4]['config_value'];
		
		$this->assign('web_name',$web_name);
		$this->assign('foot',$foot);
		$this->assign('banquan',$banquan);
		$this->assign('developer',$developer);
		$this->display();
	}
	/*
	 * right处理修改页面信息
	 */
	public function update_edit_config(){
    	header("Access-Control-Allow-Origin: *");
		$configModel = M('config');
		if ($_POST['dosubmit']){
			$result = $result | $configModel->where('config_id = 2')->setField('config_value',$_POST['web_name']);
			$result = $result | $configModel->where('config_id = 3')->setField('config_value',$_POST['foot']);
			$result = $result | $configModel->where('config_id = 4')->setField('config_value',$_POST['banquan']);
			$result = $result | $configModel->where('config_id = 5')->setField('config_value',$_POST['developer']);
		    if ($result){
				Session::set("webName",$_POST['web_name']);
		    	$msg = "修改成功!";
		    }
		    else {
		    	$msg = "修改失败!";
		    }
		}else {
		    	$msg = "数据错误!";
		}
		$this->assign("rebackMsg",$msg);
		$this->display();
	}
	/*
	 * right模块名字
	 */
	public function edit_module(){
    	header("Access-Control-Allow-Origin: *");
		$moduleModel = M("Module");
		$array = $moduleModel->select();
		$this->assign("moduleArr",$array);
		$this->display();
	}
	public function update_edit_module(){
    	header("Access-Control-Allow-Origin: *");
		$moduleModel = M('module');
		$result = false;
		if ($_POST['dosubmit']){
			for ($i = 1;$i <= 22;$i++){
				$result = $result | $moduleModel->where("module_id = $i")->setField('module_name',$_POST[$i]);
			}
		}
		if ($result){
	    	$msg = "修改成功!";
	    }
	    else {
	    	$msg = "修改失败!";
	    }
		$this->assign("rebackMsg",$msg);
		$this->display();
	}
	/*
	 * right个人信息
	 */
	public function edit_info(){				//修改信息
    	header("Access-Control-Allow-Origin: *");
    	$this->publicAssign();
    	$this->assign("userTrueName",Session::get("userTrueName"));
    	$this->assign("userEmail",Session::get("userEmail"));
		$this->display();
	}
	/*
	 * right修改个人信息
	 */
	public function update_edit_info(){
    	header("Access-Control-Allow-Origin: *");
		$infoModel = M('User');
		if ($_POST['dosubmit']){
			$data['userid'] = $_POST['userid'];
			$data['userTrueName'] = $_POST['userTrueName'];
			$data['userEmail'] = $_POST['userEmail'];
		    $result = $infoModel->save($data);
		    if ($result){
		    	$msg = "修改成功!";
		    }
		    else {
		    	$msg = "修改失败!";
		    }
		}else {
		    	$msg = "数据错误!";
		}
		$this->assign("rebackMsg",$msg);
		$this->display();
	}
	
	/*
	 * right留言板
	 */
	public function right_message(){
    	header("Access-Control-Allow-Origin: *");
		$messageModel = M('Message');
		//先计算所有留言
		$array = $messageModel->select();
		$count = count($array);
		$page = ceil($count/10);
		if ($_GET['page']){
			$upPage = $_GET['page']-1;
			$upPage = $upPage==0?1:$upPage;
			$currentPage = $_GET['page'];
			$downPage = $_GET['page']+1;
			$downPage = $downPage>$page?$page:$downPage;
			//取出留言
			$beginMessage = ($_GET['page']-1)*10;
			$array = $messageModel->limit("$beginMessage,10")->select();
		}else {
			$upPage = 1;
			$currentPage = 1;
			$downPage = 2>$page?$page:2;
			//取出留言
			$array = $messageModel->limit('0,10')->select();
		}
		$this->assign("array",$array);
		$this->assign("count",$count);
		$this->assign("page",$page);
		$this->assign("currentPage",$currentPage);
		$this->assign("upPage",$upPage);
		$this->assign("downPage",$downPage);
		$this->display();
	}
	/*
	 * right留言板内容
	 */
	public function message_comment(){
    	header("Access-Control-Allow-Origin: *");
		$msg_id = $_GET['msg_id'];
		$messageModel = M('Message');
		$msgData = $messageModel->find($msg_id);
		$this->assign("msg_comment",$msgData['msg_comment']);
		$this->display();
	}
	/*
	 * right处理留言板管理
	 */
	public function update_right_message(){
    	header("Access-Control-Allow-Origin: *");
		$msgModel = M('Message');
		for ($i = 0;$i < count($_POST['msg_id']);$i++){
			$data['msg_id'] = $_POST['msg_id'][$i];
			if ($_POST['dodelete']){
				$result = $msgModel->where($data)->delete();
			}else {
				$data['msg_state'] = $_POST['dosubmit'];
				$result = $result | $msgModel->save($data);
			}
		}
		if ($result){
			$msg = "成功!";
		}else {
			$msg = "失败!";
		}
		$this->assign("msg",$msg);
		$this->display();
	}
	/*
	 * right留言板搜索
	 */
	public function search_right_message(){
    	header("Access-Control-Allow-Origin: *");
		$messageData = M('Message');
		if ($_GET['keyword']){
			$condition[$_GET['type']] = $_GET['keyword'];
		}
		if ($_GET['status'] != "0"){
			$condition['msg_state'] = $_GET['status'];
		}
		$array = $messageData->where($condition)->select();
		
		$count = count($array);
		$page = ceil($count/10);
		if ($_GET['page']){
			$upPage = $_GET['page']-1;
			$upPage = $upPage==0?1:$upPage;
			$currentPage = $_GET['page'];
			$downPage = $_GET['page']+1;
			$downPage = $downPage>$page?$page:$downPage;
			//取出留言
			$beginMessage = ($_GET['page']-1)*10;
			$array = $messageData->where($condition)->limit("$beginMessage,10")->select();
		}else {
			$upPage = 1;
			$currentPage = 1;
			$downPage = 2>$page?$page:2;
			//取出留言
			$array = $messageData->where($condition)->limit('0,10')->select();
		}
		$this->assign("array",$array);
		$this->assign("count",$count);
		$this->assign("page",$page);
		$this->assign("currentPage",$currentPage);
		$this->assign("upPage",$upPage);
		$this->assign("downPage",$downPage);
		
		$this->display("default/admin/right_message");
	}
	/*
	 * right修改密码
	 */
	public function edit_pwd(){
    	header("Access-Control-Allow-Origin: *");
    	$this->assign("userid",Session::get('userid'));				//id
    	$this->assign("userTrueName",Session::get('userTrueName'));				//真实姓名
		$this->assign("userEmail",Session::get("userEmail"));
		$this->display();
	}
	/*
	 * right处理修改密码
	 */
	public function update_edit_pwd(){
    	header("Access-Control-Allow-Origin: *");
		$infoModel = M('User');
		if ($_POST['dosubmit']){
			if ($array = $infoModel->getByUserid($_POST['userid'])){		
				
				$old_password = md5($_POST['old_password']);					//MD5加密
				$old_password = substr($old_password, 5,12); 
				$new_password = md5($_POST['new_password']);
				$new_password = substr($new_password, 5,12); 
				
				if($array['userpwd'] == $old_password){
					$data['userid'] = $_POST['userid'];
					$data['userpwd'] = $new_password;
				    $result = $infoModel->save($data);
				    if ($result){
				    	$msg = "修改成功!";
				    }
				    else {
				    	$msg = "修改失败!注意：新旧密码不能一样!";
				    }
				}else{
				    	$msg = "旧密码错误!";
				}
			}
		}else {
		    	$msg = "数据错误!";
		}
		$this->assign("rebackMsg",$msg);
		$this->display();
	}
	/*
	 * right图片管理
	 */
	public function right_pic(){
    	header("Access-Control-Allow-Origin: *");
    	//默认教师照片
    	$dir = "../courses/public/images/teachers";
		if ($_GET['type']){
			switch ($_GET['type']){
				case "shijianjiaoxue":
					$dir = "../courses/public/images/shijianjiaoxue/pic";	
					break;
				case "jiaocai_b":
					$dir = "../courses/public/images/slidethumbs/pic_b";
					break;
				case "jiaocai_c":
					$dir = "../courses/public/images/slidethumbs/pic_s";
					break;
				case "shiyanshebei":
					$dir = "../courses/public/images/shiyanshebei";	
					break;
				default:
					break;
			}
		}
    	$fileDir = $this->getDir($dir);
    	$fileName = $this->delDirSuffix($fileDir);
    	$this->assign("dir",$dir);
    	$this->assign("fileName",$fileName);
		$this->display();
	}
	/*
	 * right显示图片
	 */
	public function pic_look(){
    	header("Access-Control-Allow-Origin: *");
		$pic_name = $_GET['pic_name'];
		$imgDir = "/".$_GET['dir']."/".$pic_name.".jpg";
		$this->assign("imgName",$pic_name);
		$this->assign("imgDir",$imgDir);
		$this->display();
	}
	public function pic_delete(){
    	header("Access-Control-Allow-Origin: *");
		for ($i = 0;$i < count($_POST['pic_name']);$i++){
			$file = $_POST['dir']."/".$_POST['pic_name'][$i].".jpg";
			if(unlink($file)){
				$msg = "删除成功!";
			}else {
				$msg = "删除失败!";
			}
		}
		$this->assign("rebackMsg",$msg);
		$this->display();
	}
	/*
	 * right会员信息
	 */
	public function right_member(){
    	header("Access-Control-Allow-Origin: *");
		$memberModel = M("User");
		$array = $memberModel->select();
		
		$count = count($array);
		$page = ceil($count/10);
		if ($_GET['page']){
			$upPage = $_GET['page']-1;
			$upPage = $upPage==0?1:$upPage;
			$currentPage = $_GET['page'];
			$downPage = $_GET['page']+1;
			$downPage = $memberModel>$page?$page:$downPage;
			//取出留言
			$beginMember = ($_GET['page']-1)*10;
			$array = $memberModel->limit("$beginMember,10")->select();
		}else {
			$upPage = 1;
			$currentPage = 1;
			$downPage = 2>$page?$page:2;
			//取出留言
			$array = $memberModel->limit('0,10')->select();
		}
		$this->assign("array",$array);
		$this->assign("count",$count);
		$this->assign("page",$page);
		$this->assign("currentPage",$currentPage);
		$this->assign("upPage",$upPage);
		$this->assign("downPage",$downPage);
		
		if (Session::get('userstyle') == C('SUPER_MANAGER')){
			$this->display("default/admin/right_member_super");
			return ;
		}
		$this->display();
	}
	/*
	 * right显示会员信息
	 */
	public function member_detail(){
    	header("Access-Control-Allow-Origin: *");
		$userID = $_GET['userid'];
		$memberModel = M("User");
		$array = $memberModel->find($userID);
		$this->assign("array",$array);
		$this->display();
	}
	/*
	 * right增加会员
	 */
	public function member_add(){
    	header("Access-Control-Allow-Origin: *");
		if ($_POST){
			$userModel = M("User");
			
			$useracc = $_POST['useracc'];
			$username = $_POST['username'];
			$userTrueName = $_POST['userTrueName'];
			$userEmail = $_POST['userEmail'];
			$userstyle = $_POST['userstyle'];
			$password = $_POST['password'];
			
			$useracc = md5($useracc);
			$useracc = substr($useracc, 5,12); 
			$password = md5($password);
			$password = substr($password, 5,12); 
			
			$data['useracc'] = $useracc;
			$data['username'] = $username;
			$data['userTrueName'] = $userTrueName;
			$data['userEmail'] = $userEmail;
			$data['userstyle'] = $userstyle;
			$data['userpwd'] = $password;
			
			$result = $userModel->add($data);
			if ($result){
				$msg = "<br /><center>成功!</center><br />";
			}else {
				$msg = "<br /><center>失败!</center><br />";
			}
			echo $msg;
		}
		
		$this->display();
	}
	/*
	 * right删除会员信息
	 */
	public function member_delete(){
    	header("Access-Control-Allow-Origin: *");
	    header("Content-Type:text/html; charset=utf-8");
	    $del = M("User");
		for ($i = 0;$i < count($_POST["userid"]);$i++){
	    	$result = $result | $del->where('userid = '.$_POST["userid"][$i])->delete();
		}
		if ($result) {
			echo "成功!";
		}
	}
	/*
	 * right更改会员信息
	 */
	public function member_update(){
    	header("Access-Control-Allow-Origin: *");
		$userID = $_GET['userid'];
		$memberModel = M("User");
		$array = $memberModel->find($userID);
		$this->assign("array",$array);
		$this->display();
	}
	/*
	 * right检查会员信息
	 */
	public function member_check(){
    	header("Access-Control-Allow-Origin: *");
		$userModel = M("User");
		
		if ($_GET['content']){
			$options[$_GET['content']] = $_GET[$_GET['content']];
			$options['userid'] = array('neq',$_GET['userid']);
			$array = $userModel->where($options)->select();
//			print_r($userModel->getLastSql());
			if (count($array) == 0){
				$msg = 1;
			}else {
				$msg = 0;
			}
		}else {
			$userid = $_POST['userid'];
			$username = $_POST['username'];
			$userTrueName = $_POST['userTrueName'];
			$userEmail = $_POST['userEmail'];
			$userstyle = $_POST['userstyle'];
			$password = $_POST['password'];
			
			$data['userid'] = $userid;
			$data['username'] = $username;
			$data['userTrueName'] = $userTrueName;
			$data['userEmail'] = $userEmail;
			$data['userstyle'] = $userstyle;
			if ($password){
				$password = md5($password);
				$password = substr($password, 5,12); 
				$data['userpwd'] = $password;
			}
			$result = $userModel->save($data);
			if ($result){
				$msg = "修改成功";
			}else {
				$msg = "修改失败";
			}
		}
		echo $msg;
	}
	/*
	 * right会员搜索
	 */
	public function search_member(){
    	header("Access-Control-Allow-Origin: *");
		$userData = M('User');
		if ($_GET['keyword']){
			$condition[$_GET['type']] = $_GET['keyword'];
		}
		if ($_GET['userstyle'] != 0){
			$condition['userstyle'] = $_GET['userstyle'];
		}
		$array = $userData->where($condition)->select();
		$this->assign("array",$array);
		$this->display("default/admin/right_member");
	}
	/*
	 * 上传图片
	 */
	public function upload_img(){
    	header("Access-Control-Allow-Origin: *");
		$dir = $_POST['dir']."/";
		
		import("ORG.Net.UploadFile");//引入类库  
        $upload=new UploadFile();//new一个对象  
        $upload->maxSize =3145728;//上传附件的大小限制,单位是字节  
        $upload->allowExts=array('jpg','doc','pdf');//上传文件的允许的类型  
        $upload->savePath = $dir;//文件的保存目录,相对于项目入口文件  
        $upload->saveRule='uniqid';//文件名称保存规则，函数名比如time.uniqid,可以是自定义函数的函数名 
        if(!$upload->upload())  
        {  
            $msg = "上传失败";  
        }else{  
            $msg = "上传成功";    
        } 
        $this->assign("rebackMsg",$msg);
        $this->display();
	}
	/*
	 * 登陆
	 */
	public function login(){				
		$config = M("Config");
    	$configArray = $config->find(2);
    	if (!Session::is_set("webName")){
    		Session::set("webName", $configArray['config_value']);
    	}	
		$this->publicAssign();
		$this->display("default/admin/login");
	}
	/*
	 * 注销
	 */
	public function logout(){					
    	header("Access-Control-Allow-Origin: *");
		header('Content-type:text/html;charset=utf-8');
		Session::destroy();
		$this->redirect("login",'',0,"页面跳转中...");
	}
	
	public function check(){			
    	header("Access-Control-Allow-Origin: *");
		header('Content-type:text/html;charset=utf-8');
		
		if (md5($_POST['code']) != Session::get('verify')) {							//判断验证码
			$this->ajaxReturn('','验证码错误！',0);
		}
		//md5
		$useracc = md5($_POST['useracc']);					//MD5加密
		$useracc = substr($useracc, 5,12); 
		$userpwd = md5($_POST['password']);
		$userpwd = substr($userpwd, 5,12); 
		
		$User = M("User");
		if ($array = $User->getByUseracc("$useracc")){			//判断账号密码
		    if($array['userpwd'] == $userpwd){
		    	$data['userid'] = $array['userid'];
		    	$data['userLoginIp'] = get_client_ip();
		    	$data['userLoginTime'] = date('Y-m-d H:i:s');
		    	$result = $User->save($data);
		    	if ($result){
		    		Session::set('userid', $array['userid']);
			    	Session::set('username', $array['username']);			//设置session
			    	Session::set('userTrueName', $array['userTrueName']);	
			    	Session::set('userEmail', $array['userEmail']);	
			    	Session::set('userstyle', $array['userstyle']);
			    	Session::set('userLoginIp', $array['userLoginIp']);
			    	Session::set('userLoginTime', $array['userLoginTime']);
			    	
					$this->ajaxReturn('','登录成功！',1);
		    	}else {
					$this->ajaxReturn('',$User->getLastSql(),4);
		    	}
		    }else{
				$this->ajaxReturn('','密码错误！',2);
		    }
		}
		$this->ajaxReturn('','账号不存在！',3);
	}
	/*
	 * 取得当前位置，在位置显示处显示出来
	 */
	public function currentPos(){
    	header("Access-Control-Allow-Origin: *");
		if ($_GET['menuid']){
			switch ($_GET['menuid']){
				case 1:
					$this->position = "网站信息";
					break;
				case 2:
					$this->position = "留言板";
					break;
				case 3:
					$this->position = "图片管理";
					break;
				case 4:
					$this->position = "会员信息";
					break;
				case 902:
					$this->position .= " > 个人信息 > 修改个人信息 >";
					break;
				case 901:
					$this->position .= " > 个人信息 > 修改密码 >";
					break;
				case 911:
					$this->position = " 网站信息 > 修改网站信息 >";
					break;
				case 912:
					$this->position = " 网站信息  > 修改模块名字 >";
					break;
				case 921:
					$this->position = " 留言板  > 留言板管理  >";
					break;
				case 931:
					$this->position = " 图片管理  > 主讲教师  >";
					break;
				case 932:
					$this->position = " 图片管理  > 实践教学  >";
					break;
				case 933:
					$this->position = " 图片管理  > 教材(大) >";
					break;
				case 934:
					$this->position = " 图片管理  > 教材(小) >";
					break;
				case 935:
					$this->position = " 图片管理  > 实验设备  >";
					break;
				case 941:
					$this->position = " 会员信息  > 会员管理  >";
					break;
				default:
					break;
			}
		}
		echo $this->position;
	}
			
	public function verify(){					//生成验证码
		import("ORG.Util.Image");
		Image::buildImageVerify();
	}
	
	public function userStyle($style){				//判断用户类型
    	header("Access-Control-Allow-Origin: *");
		if ($style == C('SUPER_MANAGER')){
			Session::set('styleName', C("SUPER_MANAGER_NAME"));
		}elseif ($style == C('NORMAL_MANAGER')){
			Session::set('styleName', C("NORMAL_MANAGER_NAME"));
		}elseif ($style == C('NORMAL_MENBER')){
			Session::set('styleName', C("NORMAL_MENBER_NAME"));
		}else {
			Session::set('styleName', "未知类型用户");
		}
	}
	public function lock(){
    	header("Access-Control-Allow-Origin: *");
		if ($_REQUEST['lock_password'] == "admin"){
			echo "1";
		}else {
			echo "0";
		}
	}
    /**
    +----------------------------------------------------------
    * 获取文件目录列表,该方法返回数组
    +----------------------------------------------------------
    */
	private function getDir($dir) {
    	header("Access-Control-Allow-Origin: *");
		$fileArray[]=NULL;
		if (false != ($handle = opendir ( $dir ))) {
			$i=0;
			while ( false !== ($file = readdir ( $handle )) ) {
				//去掉"“.”、“..”以及带“.xxx”后缀的文件
				if ($file != "." && $file != ".."&&strpos($file,".")) {
					$file = iconv("gbk", "utf-8" , $file);
					$fileArray[$i]= $file;
					if($i==100){
						break;
					}
					$i++;
				}
			}
			//关闭句柄
			closedir ( $handle );
		}
		return $fileArray;
	}
	private function delDirSuffix($array){
    	header("Access-Control-Allow-Origin: *");
		for ($i = 0;$i < count($array);$i++){
			list($name,$suffix) =  explode(".", $array[$i],2);
			$array[$i] = $name;
		}
		return $array;
	}
	/*
	 * 删除文件夹
	 */
	function deldir($dir) {
		  //先删除目录下的文件：
		  $dh=opendir($dir);
		  while ($file=readdir($dh)) {
		    if($file!="." && $file!="..") {
		      $fullpath=$dir."/".$file;
		      if(!is_dir($fullpath)) {
		          unlink($fullpath);
		      } else {
		          $this->deldir($fullpath);
		      }
		    }
		  }
		 
		  closedir($dh);
		  //删除当前文件夹：
		  if(rmdir($dir)) {
		    return true;
		  } else {
		    return false;
		  }
	}
}

?>